//
//  ViewController.m
//  18-SQLite
//
//  Created by dllo on 16/8/8.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ViewController.h"
#import "SQLiteDataBaseManger.h"
#import "Student.h"
@interface ViewController ()
@property (nonatomic, strong) SQLiteDataBaseManger *dataBaseManager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _dataBaseManager = [SQLiteDataBaseManger sharedManager];
    // SQLite3
    // 注意: 使用SQLite需要引入libsqlite3.0tbd
    // libsqlite3.0tbd 和 libsqlite3.tbd区别:
        // libsqlite3.0是libsqlite3的替身文件, 防止用户误删
    
}
- (IBAction)openSQLite:(id)sender {
    [_dataBaseManager openSQLite3];
}
- (IBAction)closeSQLite:(id)sender {
    [_dataBaseManager closeSQLite3];
}

- (IBAction)createTab:(id)sender {
    [_dataBaseManager createTable];
}
- (IBAction)insertStu:(id)sender {
    Student *stu  = [[Student alloc] init];
    stu.stu_id = 38;
    stu.stu_name = @"小日本";
    [_dataBaseManager insertStu:stu];
}
- (IBAction)deleteStu:(id)sender {
//    Student *stu = [[Student alloc] init];
//    stu.stu_id = 38;
//    stu.stu_name = @"小日本";
//    [_dataBaseManager deleteStu:stu];
    [_dataBaseManager deleteAll];
}
- (IBAction)updataStu:(id)sender {
    [_dataBaseManager updateOldName:@"小日本" newName:@"美国鬼子"];
}
- (IBAction)selectStu:(id)sender {
    NSArray *array = [_dataBaseManager selectAll];
    NSLog(@"%ld", array.count);
    NSLog(@"%@", array);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
